package com.lufei.message_system.Controller;

import com.lufei.message_system.Data.PageResult;
import com.lufei.message_system.Data.Result;
import com.lufei.message_system.Data.TestResultVD.TestResultCreateDTO;
import com.lufei.message_system.Data.TestResultVD.TestResultQueryDTO;
import com.lufei.message_system.Data.TestResultVD.TestResultUpdateDTO;
import com.lufei.message_system.Data.TestResultVD.TestResultVO;
import com.lufei.message_system.Service.TestResultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/testResults")
public class TestResultController {
    @Autowired
    private TestResultService testResultService;

    // 创建接口（保持不变）
    @PostMapping
    public Result<TestResultVO> createTestResult(@RequestBody TestResultCreateDTO createDTO) {
        return testResultService.createTestResult(createDTO);
    }

    // ========== 按记录ID操作的接口 ==========

    @GetMapping("/byId/{id}")
    public Result<TestResultVO> getTestResultById(@PathVariable Long id) {
        return testResultService.getTestResultById(id);
    }

    @PutMapping("/byId")
    public Result<TestResultVO> updateTestResultById(@RequestBody TestResultUpdateDTO updateDTO) {
        return testResultService.updateTestResultById(updateDTO);
    }

    @DeleteMapping("/byId/{id}")
    public Result<Boolean> deleteTestResultById(@PathVariable Long id) {
        return testResultService.deleteTestResultById(id);
    }

    // ========== 按用户ID操作的接口 ==========

    @GetMapping("/byUserId/{userId}")
    public Result<List<TestResultVO>> getTestResultsByUserId(@PathVariable String userId) {
        return testResultService.getTestResultsByUserId(userId);
    }

    @PutMapping("/byUserId/{userId}")
    public Result<List<TestResultVO>> updateTestResultsByUserId(
            @PathVariable String userId,
            @RequestBody TestResultUpdateDTO updateDTO) {
        return testResultService.updateTestResultsByUserId(userId, updateDTO);
    }

    @DeleteMapping("/byUserId/{userId}")
    public Result<Boolean> deleteTestResultsByUserId(@PathVariable String userId) {
        return testResultService.deleteTestResultsByUserId(userId);
    }

    // ========== 通用查询接口（保持不变） ==========

    @GetMapping
    public PageResult<TestResultVO> queryTestResults(TestResultQueryDTO queryDTO) {
        return testResultService.queryTestResults(queryDTO);
    }
}